import urllib3
import re

url = 'http://image.baidu.com/search/index?ct=201326592&cl=2&st=-1&lm=-1&nc=1&ie=utf-8&tn=baiduimage&ipn=r&rps=1&pv=&fm=rs3&word=%E5%9B%BE%E7%89%87%E4%BC%A0%E8%AF%B4&oriquery=%E5%9B%BE%E7%89%87&ofr=%E5%9B%BE%E7%89%87&sensitive=0'

http = urllib3.PoolManager()

html_url = http.request('GET', url)

text = html_url.data.decode("UTF-8")
# print(html_url.data.decode("UTF-8"))

res = re.findall(r'"thumbURL":"(.*?)"', text)
print(len(res))
print()

headers ={
    "Referer": "http://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E5%9B%BE%E7%89%87%E4%BC%A0%E8%AF%B4&step_word=&hs=0&pn=1&spn=0&di=17160&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=-1&cs=3893735857%2C2598881471&os=4280333741%2C3064363095&simid=4223527937%2C396246798&adpicid=0&lpn=0&ln=1332&fr=&fmq=1580986355925_R&fm=rs3&ic=undefined&s=undefined&hd=undefined&latest=undefined&copyright=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=%E5%9B%BE%E7%89%87&objurl=http%3A%2F%2Fimg.pcgames.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fgamephotolib%2F1607%2F05%2Fc0%2F15705680_1467708527712_medium.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fri5p5f_z%26e3Brv2w4jf_z%26e3Bv54_z%26e3BvgAzdH3F2657rAzdH3F0mnmc0_z%26e3Bip4s&gsm=&rpstart=0&rpnum=0&islist=&querylist=&force=undefined",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
}

for index, image in enumerate(res):
    image_data = http.request("GET", image, headers=headers)
    print(image)
    image_name = '%s.%s' % (index+1, image.split('.')[-1])
    with open(image_name, 'wb') as f:
        f.write(image_data.data)
